package cn.edu.baiyunu.myapplication.ui.home

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowForward
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import cn.edu.baiyunu.myapplication.data.db.entity.PhotoRecord
import cn.edu.baiyunu.myapplication.data.model.PhotoSpec
import cn.edu.baiyunu.myapplication.ui.components.WelcomeBanner

/**
 * 首页内容组件 - 按照原型图样式重新设计
 */
@Composable
fun HomeContent(
    viewModel: HomeViewModel,
    paddingValues: PaddingValues,
    onNavigateToUpload: () -> Unit,
    onNavigateToSpecs: () -> Unit,
    onNavigateToHistory: () -> Unit,
    onPhotoClick: (PhotoRecord) -> Unit,
    onSpecClick: (PhotoSpec) -> Unit
) {
    val recentPhotos by viewModel.recentPhotos.observeAsState(emptyList())
    
    LazyColumn(
        modifier = Modifier
            .fillMaxSize()
            .padding(paddingValues)
            .padding(horizontal = 16.dp)
            .background(Color.White)
    ) {
        // 欢迎横幅
        item {
            WelcomeBanner(
                onCreateClick = onNavigateToUpload
            )
            Spacer(modifier = Modifier.height(16.dp))
        }
        
        // 热门规格
        item {
            SpecsSection(
                specs = viewModel.popularSpecs,
                onSeeAllClick = onNavigateToSpecs,
                onSpecClick = onSpecClick
            )
            Spacer(modifier = Modifier.height(16.dp))
        }
        
        // 功能特点
        item {
            FeaturesSection(
                features = viewModel.getFeatures()
            )
            Spacer(modifier = Modifier.height(16.dp))
        }
        
        // 使用流程
        item {
            UsageFlowSection(
                usageFlows = viewModel.getUsageFlows()
            )
            Spacer(modifier = Modifier.height(24.dp))
        }
        
        // 开始制作按钮 - 修复版本
        item {
            Box(
                modifier = Modifier.fillMaxWidth(),
                contentAlignment = Alignment.Center
            ) {
                Button(
                    onClick = onNavigateToUpload,
                    shape = RoundedCornerShape(12.dp),
                    colors = ButtonDefaults.buttonColors(
                        containerColor = MaterialTheme.colorScheme.primary
                    ),
                    modifier = Modifier
                        .height(56.dp)
                ) {
                    Text(
                        text = "开始制作",
                        fontWeight = FontWeight.SemiBold,
                        fontSize = 18.sp
                    )
                    Spacer(modifier = Modifier.width(8.dp))
                    Icon(
                        imageVector = Icons.AutoMirrored.Filled.ArrowForward,
                        contentDescription = null
                    )
                }
            }
            Spacer(modifier = Modifier.height(32.dp))
        }
        
        // 最近照片（如果有）
        if (recentPhotos.isNotEmpty()) {
            item {
                RecentPhotosSection(
                    photos = recentPhotos,
                    onPhotoClick = onPhotoClick,
                    onSeeAllClick = onNavigateToHistory
                )
                Spacer(modifier = Modifier.height(80.dp)) // 为底部导航栏留出空间
            }
        } else {
            item {
                Spacer(modifier = Modifier.height(80.dp)) // 为底部导航栏留出空间
            }
        }
    }
} 